package com.gym.code.config.admin.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gym.code.config.admin.bean.method.MethodColumnMappingBaseBean;
import com.gym.code.config.admin.bean.method.MethodColumnMappingBean;
import com.gym.code.config.admin.dao.IColumnMappingDao;
import com.gym.code.config.admin.dao.IMethodColumnMappingDao;
import com.gym.code.config.admin.service.IMethodColumnMappingService;

/**
 * 
 * @author xinchun.wang
 * @email: 532002108@qq.com
 * @createTime 2015-4-11 下午4:39:36
 */
@Service
public class MethodColumnMappingService implements IMethodColumnMappingService{

	@Autowired
	private IMethodColumnMappingDao functionColumnMappingDao;
	
	@Autowired
	private IColumnMappingDao columnMappingDao;
	
	@Override
	public int insert(MethodColumnMappingBaseBean bean) {
		return functionColumnMappingDao.insert(bean);
	}

	@Override
	public MethodColumnMappingBaseBean queryBase(int id) {
		return functionColumnMappingDao.queryBase(id);
	}

	@Override
	public List<MethodColumnMappingBaseBean> queryBaseByMethodId(long methodId) {
		return functionColumnMappingDao.queryBaseByMethodId(methodId);
	}

	@Override
	public void insert(List<MethodColumnMappingBaseBean> beanList) {
		for(MethodColumnMappingBaseBean item : beanList){
			this.insert(item);
		}
	}

	private MethodColumnMappingBean wrapMethodColumnMappingBean(MethodColumnMappingBaseBean baseBean){
		MethodColumnMappingBean bean = new MethodColumnMappingBean(baseBean);
		bean.setColumnMappingBean(columnMappingDao.query(baseBean.getColumnId()));
		return bean;
	}
	
	@Override
	public MethodColumnMappingBean query(int id) {
		return wrapMethodColumnMappingBean(queryBase(id));
	}

	@Override
	public List<MethodColumnMappingBean> queryByMethodId(long methodId) {
		List<MethodColumnMappingBaseBean> baseList = queryBaseByMethodId(methodId);
		List<MethodColumnMappingBean> result = new ArrayList<MethodColumnMappingBean>();
		for(MethodColumnMappingBaseBean item : baseList){
			result.add(wrapMethodColumnMappingBean(item));
		}
		return result;
	}

}
